/***************************************************************************************
 * Copyright (c) 2014-2024 Zihao Yu, Nanjing University
 *
 * NEMU is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *
 * See the Mulan PSL v2 for more details.
 ***************************************************************************************/

#include <common.h>
#include <string.h>
#include "monitor/sdb/sdb.h"
void init_monitor(int, char *[]);
void am_init_monitor();
void engine_start();
int is_exit_status_bad();

int main(int argc, char *argv[])
{
  /* Initialize the monitor. */
#ifdef CONFIG_TARGET_AM
  am_init_monitor();
#else
  init_monitor(argc, argv);
#endif

  // const char *file_path = "/home/cgbc/Desktop/ysyx-workbench/nemu/testscripts/output.txt";

  // FILE *fp = fopen(file_path, "r");
  // if (!fp)
  // {
  //   fprintf(stderr, "Error: cannot open file %s\n", file_path);
  //   return 1;
  // }
  // // 用于读取表达式和结果
  // char expression[1024];
  // char result[1024];
  // word_t cnt = 0;

  // // 循环按“表达式-结果”两行来读取
  // while (1)
  // {
  //   printf("Test case %d\n", ++cnt);
  //   //跳过空行
  //   if (!fgets(expression, sizeof(expression), fp))
  //   {
  //     break;
  //   }
  //   // 读取表达式
  //   if (!fgets(expression, sizeof(expression), fp))
  //   {
  //     break;
  //   }
  //   // 删除表达式末尾的换行符
  //   expression[strcspn(expression, "\n")] = '\0';
  //   // 读取结果
  //   if (!fgets(result, sizeof(result), fp))
  //     break;

  //   // 打印表达式和结果
  //   printf("Expression: %sResult: %s", expression, result);

  //   // 调用你的解析函数
  //   bool success = false;
  //   word_t result_int = expr(expression, &success);
  //   if (!success)
  //   {
  //     printf("Error: expr() returns NULL\n");
  //     fclose(fp);
  //     return 1;
  //   }

  //   word_t result_expected = strtoul(result, NULL, 10);

  //   if (result_int == (word_t)result_expected)
  //   {
  //     printf("Success: The result matches.\n");
  //   }
  //   else
  //   {
  //     printf("Failure: Expected %u but got %u.\n", result_expected, result_int);
  //     fclose(fp);
  //     return 1;
  //   }
  // }

  // fclose(fp);

  engine_start();

  return is_exit_status_bad();
}
